<%@ page language="java" import="java.util.*,com.xiaobin.system.util.*"
	pageEncoding="UTF-8"%>
<%@ include file="/base/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>${systemOption.systemTitle}</title>
<%@ include file="/base/head.jsp"%>	

 <script language="javascript" src="${ctx}/js/LodopFuncs.js"></script>
    <script type="text/javascript" charset="UTF-8">
		//分页查询
	function doQuery() {
		var queryParams = $('#mailList').datagrid('options').queryParams;
		queryParams.startSendTime = $('#searchfromTime').datebox('getValue');
		queryParams.endSendTime = $('#searchtoTime').datebox('getValue');
		queryParams.recieve = $('#reciveName').val();
		//重置当前页数为1
		resetDG('#mailList');
	}
	function formatRQ(val,row){
 		if(val!=null){
			return val.replace('T',' ');
		}
 	}
 	//删除
	function del_msg() {
		var ids="";
		var slt=$('#mailList').datagrid('getSelections');
		if (slt.length==0) {
			$.messager.alert('友情提示', '请选择消息', 'error');
		} else {
			$.messager.confirm('友情提示', '将删除该消息，确定么？', function(r) {
				if (r) {
					for(var i = 0;i<slt.length;i++){
						var row=slt[i];
						ids=ids+","+row.id;
					}
					ids=ids.substring(1);
					$.post("${ctx}/json/removeReciveMsg.action", {
						"ids" : ids
					}, function(data) {
						if (data) {
							$.messager.alert('友情提示', '删除成功', 'info');
							$('#msgList').datagrid('reload');
						} else {
							$.messager.alert('友情提示', '删除失败', 'error');
						}
					}, "json");
				}
			});

		}
	}
		//详情
 function detail(){
 	var row = $('#mailList').datagrid('getSelected');
 	$('#tdFuJian').text('');
 	$('#xqdlg').show();
 	$('#xqdlg').dialog({
 			title:'邮件详情',
        	modal:true,
        	maximizable:true,
        	buttons: [{
			text:'关闭',
			iconCls:'icon-cancel',
			handler:function(){
				$('#xqdlg').dialog('close');
			}
		}]
 	});
 	//加载数据
    $.post("${ctx}/json/viewMail.action", {"id": row.id },
		function(data){
		if(data){
			var fjrmc = data.fjrmc+'['+data.fromMail+']';
			$('#showFjrmc').html(fjrmc);
			$('#showsendTime').html(data.sendTime);
			$('#showSubject').html(data.subject);
			$('#showSjrName').html(data.jsrName);
			if(data.fujian!=null && data.fujian !=''){
				$("#showFujian").show();
				var fujianName = data.fujianName;
				var fujian = data.fujian;
				var f = fujianName.split(',');
				var fname = fujian.split(',');
				var td='';
				for(var i = 0;i<f.length;i++){
					td+="<div><a id='showfujianId' href='#' onclick='downFujian(\""+fname[i]+"\")' style='color:blue;'>"+f[i]+"</a></div>";
				}
				$('#tdFuJian').append(td);
				$('#fujianSpan').html(data.fujian);
			}
			$('#contentId').html(data.content);
		}else{
			$.messager.alert('友情提示','加载失败','error');
		}
	}, "json");
 }
 function formatStatus(val,row){
		if(row.isnew==0){
			return '<img alt="新邮件" src="${ctx }/images/icon/16/email.png">';
		}else{
			return '<img alt="已读邮件" src="${ctx }/images/icon/16/email_open.png">';
		}
	}
	/**附件下载*/
function downFujian(fujian){
	 window.location.href='${ctx}/zhgl/downFujian.action?fujian='+encodeURI(encodeURI(fujian));
}
//删除邮件
function delMessage(){
	var row = $('#mailList').datagrid('getSelected');
	if(!row){
		$.messager.alert('友情提示', '请选择要删除的行', 'error');
		return;
	}
	$.messager.confirm('友情提示', '将删除，确定么？', function(r) {
			if (r) {
				$.post("${ctx}/json/delMail.action", {
					"id" : row.id
				}, function(data) {
					if (data) {
						$.messager.alert('友情提示', '删除成功', 'info');
						resetDG('#mailList');
				} else {
						$.messager.alert('友情提示', '删除失败', 'error');
				}
			}, "json");
		}
	});
}
	</script>

  </head>
  
  <body>

        <!-- 主窗口 -->  	 
  	  <table id="mailList" class="easyui-datagrid" data-options="fit:true,
	    								rownumbers:true,
										singleSelect:true,
										striped:true,
										fitColumns:true,
										border:false,
										toolbar:'#tb',
										pagination:true,
										pageSize:20,
										nowrap:true,
										url:'${ctx}/json/listSendMail.action?isSave=2',
										onDblClickRow:detail">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true"></th>
					<th data-options="field:'jsrmc',align:'left'" width="400px"><strong>收件人</strong></th>
					<th data-options="field:'subject',align:'left'" width="500px"><strong>主题</strong></th>
					<th data-options="field:'sendTime',align:'center'" width="150px"><strong>发件时间</strong></th>
					<th data-options="field:'id',hidden:true"></th>
				</tr>
			</thead>
		</table>
		<!-- Datagrid工具栏 -->
		<div id="tb">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td class="toolDiv"><a href="javascript:void(0)" onclick="delMessage()" class="easyui-linkbutton" data-options="iconCls:'icon-email-delete',plain:true" style="float:left;">删除</a>
					</td>
				</tr>
				<tr>
					<td class="serchDiv"> 
						收件人：<input id="reciveName" class="easyui-validatebox" type="text"  style="width:200px">
						&nbsp;&nbsp;发件时间：
						<input id="searchfromTime" class="easyui-datebox" />至<input id="searchtoTime" class="easyui-datebox"/>
						&nbsp;&nbsp;<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" 
										onclick="doQuery()">查询</a>
					</td>
				</tr>
			</table>
		</div>
		<!-- 详情窗口 -->    
		<div id="xqdlg" style="width:750px;height:400px;overflow-x:hidden;overflow-y:auto;display: none">
				<table class="dlgtb" width="100%" cellpadding=0 cellspacing=0 style="overflow-x:hidden;overflow-y:auto;">
					<tr height="30px">
						<td class="lbl" height="60px" width="10%">发件人</td>
						<td  height="30px" width="90%"><span id="showFjrmc"></span></td>
					</tr>
					<tr height="30px">
						<td class="lbl" height="60px">收件人</td>
						<td  height="30px"><span id="showSjrName"></span></td>
					</tr>
					<tr height="30px">
						<td class="lbl" height="30px">时间</td>
						<td width="80%"><span id="showsendTime"  height="30px"></span></td>
					</tr>
					<tr height="30px">
						<td class="lbl" height="60px">主题</td>
						<td  height="30px"><span id="showSubject"></span></td>
					</tr>
					<tr id="showFujian" style="display: none" height="30px">
						<td class="lbl"  height="60px">附件</td>
						<td id="tdFuJian"></td>
					</tr>
					<tr>
						<td colspan="2" valign="top" id="contentId" style="border: 0px;">
						</td>
					</tr>
				</table>
		</div>
  </body>
</html>
